﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
using System.Collections.Generic;
using System.IO;
public partial class Admin_webConfig : basePage
{       
    Webconfig web = new Webconfig();
    WebconfigBll webBll = new WebconfigBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            IList<Webconfig> list = webBll.GetModel();
            if (list.Count == 0)
            {
                JsUtil.ShowMsg("数据丢失", "DotNetMain.aspx");
                return;
            }
            foreach (Webconfig w in list)
            {
            
                this.tueijianTxt.Value = w.featuredProductsNum.ToString();
                this.renmenTxt.Value = w.hotProductsNum.ToString();
                this.zueixinTxt.Value = w.newProductsNum.ToString();
                this.xinwenTxt.Value = w.NewsNum.ToString();
                this.shueijiTxt.Value = w.randomProductsNum.ToString();
                this.zxinwenTxt.Value = w.newNewsNum.ToString();
                this.chanpinTxt.Value = w.productsListNum.ToString();

                #region 获得路径下面的皮肤供选择
                DirectoryInfo dir = new DirectoryInfo(Server.MapPath(@"~/DotNet_net/Skins/"));
                foreach (DirectoryInfo subdir in dir.GetDirectories())
                {
                    ListItem li = new ListItem();
                    li.Text = subdir.Name;
                    li.Value = subdir.Name;
                    this.DropDownListskin.Items.Add(li);
                }
                #endregion
                this.DropDownListskin.SelectedValue = w.Skins;
                if (w.webKey.Length>0)
                {
                    string[] hotKey = w.webKey.Split('■');
                    #region 给关键字控件复制
                    this.guanjianTxt0.Value = hotKey[0];
                    this.guanjianTxt1.Value = hotKey[1];
                    this.guanjianTxt2.Value = hotKey[2];
                    this.guanjianTxt3.Value = hotKey[3];
                    this.guanjianTxt4.Value = hotKey[4];
                    this.guanjianTxt5.Value = hotKey[5];
                    this.guanjianTxt6.Value = hotKey[6];
                    this.guanjianTxt7.Value = hotKey[7];
                    this.guanjianTxt8.Value = hotKey[8];
                    this.guanjianTxt9.Value = hotKey[9];
                    this.guanjianTxt10.Value = hotKey[10];
                    this.guanjianTxt11.Value = hotKey[11];
                    this.guanjianTxt12.Value = hotKey[12];
                    this.guanjianTxt13.Value = hotKey[13];
                    this.guanjianTxt14.Value = hotKey[14];
                    this.guanjianTxt15.Value = hotKey[15];
                    this.guanjianTxt16.Value = hotKey[16];
                    this.guanjianTxt17.Value = hotKey[17];
                    this.guanjianTxt18.Value = hotKey[18];
                    this.guanjianTxt19.Value = hotKey[19];
                    this.guanjianTxt20.Value = hotKey[20];
                    this.guanjianTxt21.Value = hotKey[21];
                    this.guanjianTxt22.Value = hotKey[22];
                    this.guanjianTxt23.Value = hotKey[23];
                    this.guanjianTxt24.Value = hotKey[24];
                    this.guanjianTxt25.Value = hotKey[25];
                    this.guanjianTxt26.Value = hotKey[26];
                    this.guanjianTxt27.Value = hotKey[27];
                    this.guanjianTxt28.Value = hotKey[28];
                    this.guanjianTxt29.Value = hotKey[29];
                }               
                #endregion  
                this.tongjiTxt.Value = w.webCount.ToString();
                this.banquanTxt.Value = w.Copyright.ToString();
                this.Indexptxt.Value = w.IndexProductsNum.ToString();
                this.HiddenId.Value = w.webId.ToString();
            }
        }
    }
    public string GetAllFolder(string path)
    {
        string folder_Names = "";
        DirectoryInfo dir = new DirectoryInfo(path);

        foreach (DirectoryInfo subdir in dir.GetDirectories())
            folder_Names += subdir.Name + ",";
        return folder_Names;
    }  
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            web.featuredProductsNum = Convert.ToInt32(this.tueijianTxt.Value);
            web.hotProductsNum = Convert.ToInt32(this.renmenTxt.Value);
            web.newProductsNum = Convert.ToInt32(this.zueixinTxt.Value);
            web.NewsNum = Convert.ToInt32(this.xinwenTxt.Value);
            web.randomProductsNum = Convert.ToInt32(this.shueijiTxt.Value);
            web.newNewsNum = Convert.ToInt32(this.zxinwenTxt.Value);
            web.productsListNum = Convert.ToInt32(this.chanpinTxt.Value);
            web.Skins = this.DropDownListskin.SelectedValue;
            web.IndexProductsNum =Convert.ToInt32(this.Indexptxt.Value);
       
            web.webCount=this.tongjiTxt.Value;
            web.webId=Convert.ToInt32(this.HiddenId.Value);            
            web.Copyright = this.banquanTxt.Value;

            #region 关键字
            web.webKey = this.guanjianTxt0.Value + "■";
            web.webKey += this.guanjianTxt1.Value + "■";
            web.webKey += this.guanjianTxt2.Value + "■";
            web.webKey += this.guanjianTxt3.Value + "■";
            web.webKey += this.guanjianTxt4.Value + "■";
            web.webKey += this.guanjianTxt5.Value + "■";
            web.webKey += this.guanjianTxt6.Value + "■";
            web.webKey += this.guanjianTxt7.Value + "■";
            web.webKey += this.guanjianTxt8.Value + "■";
            web.webKey += this.guanjianTxt9.Value + "■";
            web.webKey += this.guanjianTxt10.Value + "■";
            web.webKey += this.guanjianTxt11.Value + "■";
            web.webKey += this.guanjianTxt12.Value + "■";
            web.webKey += this.guanjianTxt13.Value + "■";
            web.webKey += this.guanjianTxt14.Value + "■";
            web.webKey += this.guanjianTxt15.Value + "■";
            web.webKey += this.guanjianTxt16.Value + "■";
            web.webKey += this.guanjianTxt17.Value + "■";
            web.webKey += this.guanjianTxt18.Value + "■";
            web.webKey += this.guanjianTxt19.Value + "■";
            web.webKey += this.guanjianTxt20.Value + "■";
            web.webKey += this.guanjianTxt21.Value + "■";
            web.webKey += this.guanjianTxt22.Value + "■";
            web.webKey += this.guanjianTxt23.Value + "■";
            web.webKey += this.guanjianTxt24.Value + "■";
            web.webKey += this.guanjianTxt25.Value + "■";
            web.webKey += this.guanjianTxt26.Value + "■";
            web.webKey += this.guanjianTxt27.Value + "■";
            web.webKey += this.guanjianTxt28.Value + "■";
            web.webKey += this.guanjianTxt29.Value + "■";
            if (web.webKey.Length>300)
            {
                ClientScript.RegisterClientScriptBlock(GetType(), "a", "<script>alert('关键字总长过长，请修改关键字！');</script>");
                return;
            }
            #endregion

            if (webBll.Update(web))
            {
                JsUtil.ShowMsg("修改成功");
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        catch
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        finally
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
    }
}
